<template>
  <div class="special" :v-if="specialShow">
    <div id="special-content" style="height: 300px">
      <div class="item-title">{{ service.name }}</div>
      <div class="item-list">
        <div
          :class="serviceId==item.id? 'item border-half-px chosen':'item border-half-px'"
          v-for="item in service.subItems"
          :key="item.id"
          @click="serviceChosen(item)"
        >
          {{ item.name }}
        </div>
      </div>
      <div class="item-title">{{ hallType.name }}</div>
      <div class="item-list">
        <div
          :class="hallTypeId==item.id? 'item border-half-px chosen':'item border-half-px'"
          v-for="item in hallType.subItems"
          :key="item.id"
          @click="hallTypeChosen(item)"
        >
          {{ item.name }}
        </div>
      </div>
    </div>
    <div id="special-btn">
      <span class="btn border-half-px" id="cancel-btn" @click="resetBtn">重置</span>
      <span class="btn" id="confirm-btn" @click="submitBtn">确定</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "Special",
  props: {
    specialShow: {
      type: Boolean,
      default: false,
    },
    hallType: {
      type: Object,
    },
    service: {
      type: Object,
    },
    cinemaVal:{
      type:Object
    }
  },
  data(){
    return{
      serviceId:this.cinemaVal.serviceId,
      serviceName:this.cinemaVal.specialName.split(',')[0]||'',
      hallTypeId:this.cinemaVal.hallTypeId,
      hallTypeName:this.cinemaVal.specialName.split(',')[1]||'',
    }
  },
  methods:{
    serviceChosen(val){
      this.serviceId = val.id;
      if(this.serviceId === -1){
        this.serviceName = '';
      }else{
        this.serviceName = val.name;
      }
    },
    hallTypeChosen(val){
      this.hallTypeId = val.id;
      if(this.hallTypeId === -1){
        this.hallTypeName = '';
      }else{
        this.hallTypeName = "," + val.name;
      }
    },
    resetBtn(){
      this.serviceId = -1;
      this.hallTypeId = -1;
      this.serviceName = '';
      this.hallTypeName = '';
    },
    submitBtn(){
      this.cinemaVal['hallTypeId'] = this.hallTypeId;
      this.cinemaVal['serviceId'] = this.serviceId;
      this.cinemaVal.isLoad = !this.cinemaVal.isLoad;
      this.cinemaVal['specialName'] = this.serviceName + this.hallTypeName;
      this.$emit('cinemaVal',this.cinemaVal);
    }
  }
};
</script>

<style lang="scss" scoped>
body {
  color: #777;
}
.special {
  background-color: #fff;
  overflow: auto;
  z-index: 999;
  .border-half-px {
    position: relative;
  }
  .border-half-px::after {
    content: "";
    position: absolute;
    width: 200%;
    height: 200%;
    top: 0;
    left: 0;
    -webkit-transform-origin: 0 0;
    transform-origin: 0 0;
    border: 1px solid #e5e5e5;
    -webkit-transform: scale(0.5);
    transform: scale(0.5);
    border-radius: 6px;
    box-sizing: border-box;
    pointer-events: none;
  }
  #special-content {
    min-height: 150px;
    max-height: 381px;
    overflow: overlay;
    .item-title {
      margin-left: 13px;
      margin-top: 13px;
      color: #333;
      font-size: 15px;
      line-height: 21px;
      margin-bottom: 13px;
    }
    .item-list {
      margin: 0 13px 13px;
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      grid-gap: 10px;
      .item {
        padding: 0 4px;
        width: 80px;
        height: 32px;
        line-height: 32px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        text-align: center;
        font-size: 13px;
        box-sizing: border-box;
        color: #666;
      }
      .chosen {
        background: #fcf0f0;
        border: 1px solid #dd403b;
        border-radius: 3px;
        box-sizing: border-box;
        color: #dd403b;
      }
    }
  }
  #special-btn {
    display: flex;
    -webkit-box-pack: justify;
    justify-content: space-between;
    height: 56px;
    width: 100%;
    background: #fff;
    .btn {
      display: inline-block;
      height: 34px;
      width: 67px;
      margin-left: 12px;
      margin-top: 11px;
      text-align: center;
      line-height: 34px;
      font-size: 14px;
      color: #666;
    }
    #confirm-btn {
      margin-right: 12px;
      background: #dd403b;
      border-radius: 3px;
      color: #fff;
    }
  }
}
</style>